package com.example.commonmybatisplus.utils.injector;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.example.commonmybatisplus.utils.injector.DefineSqlInjector;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * @Author ifredomvip@gmail.com
 * @Date 2022/5/30 11:11
 * @Version 1.0.0
 * @Description
 * 源码位置： https://sourcegraph.com/github.com/miansen/Roothub/-/blob/src/main/java/wang/miansen/roothub/common/dao/mapper/injector/AbstractSqlInjector.java?L56
 * 源码解读： https://sourcegraph.com/github.com/wujun728/jun_weixin/-/blob/weixin_mybatis_plus/mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/AbstractMethod.java?L26
 **/
@Component
public class RegisterSqlInjector extends DefaultSqlInjector {

    /**
     * 根据 mapperClass 注入 SQL，需要检查 SQL 是否已注入(已经注入过不再注入)
     *
     * @param mapperClass mapper类
     * @param tableInfo   tableInfo
     */
    @Override
    public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {
        List<AbstractMethod> methodList = super.getMethodList(mapperClass, tableInfo);
//        methodList.forEach(System.out::println);

        methodList.add(new DefineSqlInjector());
        methodList.add(new Define2SqlInjector());
        return methodList;
    }

}